package org.hs.phd.common.simpleplayer.filter;

import static com.googlecode.javacv.cpp.opencv_core.cvCopy;

import java.awt.Rectangle;

import org.hs.phd.common.simpleplayer.ImageSequenceFrame;
import org.hs.phd.common.simpleplayer.PlayerFilter;

import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.IplImage;

public class CropFilter implements PlayerFilter{

	private final Rectangle cropArea;

	public CropFilter(Rectangle cropArea) {
		this.cropArea = cropArea;
	}

	@Override
	public void filter(ImageSequenceFrame inputFrame) {
		IplImage input = inputFrame.getFrameImage();
		opencv_core.cvSetImageROI(input, opencv_core.cvRect(cropArea.x, cropArea.y, cropArea.width, cropArea.height));
		IplImage result = opencv_core.cvCreateImage(opencv_core.cvSize(cropArea.width, cropArea.height), input.depth(), input.nChannels());
		cvCopy(input, result);
		inputFrame.setFrameImage(result);
	}

}
